package com.googlecode.mgwt.examples.uibinder.client.activities;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.googlecode.mgwt.examples.uibinder.client.ClientFactory;
import com.googlecode.mgwt.examples.uibinder.client.places.ExamplePlace.ID;
import com.googlecode.mgwt.examples.uibinder.client.places.ExampleSourcePlace;
import com.googlecode.mgwt.examples.uibinder.client.places.HomePlace;
import com.googlecode.mgwt.mvp.client.MGWTAbstractActivity;
import com.googlecode.mgwt.ui.client.MGWTUtil;

public class ExampleActivity extends MGWTAbstractActivity implements ExampleDisplay.Presenter {

	private final ExampleDisplay display;
	private final ClientFactory clientFactory;
	private final ID id;

	public ExampleActivity(ClientFactory clientFactory, ExampleDisplay display, ID id) {
		this.clientFactory = clientFactory;
		this.display = display;
		this.id = id;

	}

	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus) {
		panel.setWidget(display);
		display.setPresenter(this);
	}

	@Override
	public void onStop() {
		display.setPresenter(null);
	}

	@Override
	public void onBackButtonPressed() {
		if (MGWTUtil.getFeatureDetection().isPhone() || MGWTUtil.getFeatureDetection().isDesktop()) {
			clientFactory.getPlaceController().goTo(new HomePlace());
		}
	}

	@Override
	public void onSourceButtonPressed() {
		clientFactory.getPlaceController().goTo(new ExampleSourcePlace(id));

	}

}
